﻿using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using UnityEngine;

public class TestHashSet : MonoBehaviour
{
    public HashSet<string> hash = new HashSet<string>();
    List<string> list = new List<string>();
    Dictionary<int, string> id = new Dictionary<int, string>();
    // Start is called before the first frame update
    void Start()
    {
        Stopwatch stopwatch = new Stopwatch();
        stopwatch.Start();
        for (int i = 0; i < 500; i++)
        {
            hash.Add(i.ToString());
        }
        stopwatch.Stop();
        UnityEngine.Debug.Log("hash="+stopwatch.ElapsedTicks);
        stopwatch.Restart();
        for (int i = 0; i < 500; i++)
        {
            list.Add(i.ToString());
        }
        stopwatch.Stop();
        UnityEngine.Debug.Log("list="+stopwatch.ElapsedTicks);

        stopwatch.Restart();
        foreach (string item in list)
        {
            if (item=="300")
            {
                break;
            }
        }
        stopwatch.Stop();
        UnityEngine.Debug.Log("查找list=" + stopwatch.ElapsedTicks);
        stopwatch.Restart();
        foreach (string item in hash)
        {
            if (item=="300")
            {
                break;
            }
        }
        stopwatch.Stop();
        UnityEngine.Debug.Log("查找hash=" + stopwatch.ElapsedTicks);
        stopwatch.Restart();
        if (hash.Contains("300"))
        {
            stopwatch.Stop();
            UnityEngine.Debug.Log("查找Contains hash=" + stopwatch.ElapsedTicks);
        }
        stopwatch.Restart();
        for (int i = 0; i < 500; i++)
        {
            id.Add(i,i.ToString());
        }
        stopwatch.Stop();
        UnityEngine.Debug.Log("Dictionary=" + stopwatch.ElapsedTicks);




    }

    // Update is called once per frame
    void Update()
    {
        
    }
}
